﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using NetFramework;

namespace DataExchangeWebService
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class MainService : System.Web.Services.WebService
    {
        private SocketClient _client = new SocketClient();
        private IAsyncResult iar;

        public MainService()
        {
            //iar = _client.Connect("127.0.0.1", 8089);
        }

        [WebMethod]
        public void GetInfo()
        {
            //byte[] cmd = System.Text.Encoding.Unicode.GetBytes("gets");
            //_client.Send(cmd);

            //byte[] cmdnum = { 0x01, 0x02 };
            //_client.Send(cmdnum);
        }


        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public Person GetPerson()
        {
            Person u = new Person();
            return u;
            //"{'user':{'id':'0','name':'','message':'0','ipoint':'0','gpoint':'0'}}";
            //return "Hello World";
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public List<Person> GetPersonList()
        {
            List<Person> lstPerson = new List<Person>();
            for (int i = 0; i < 10; i++)
            {
                Person u = new Person();
                u.Name = i.ToString();
                u.Age = i;
                lstPerson.Add(u);
            }

            return lstPerson;
            //"{'user':{'id':'0','name':'','message':'0','ipoint':'0','gpoint':'0'}}";
            //return "Hello World";
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public string HelloWorldString()
        {
            //return "{'user':{'id':'0','name':'','message':'0','ipoint':'0','gpoint':'0'}}";
            return "Hello World";
        }

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public string HelloWorld(string name)
        {
            //return "{'user':{'id':'0','name':'','message':'0','ipoint':'0','gpoint':'0'}}";
            return "Hello World"+" "+name;
        }

    }

    public class Person
    {
        private string name = "name#1";
        private int age = 20;
        public string Name { get { return name; } set { name = value; } }

        public int Age { get { return age; } set { age = value; } }
    }

}
